<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="http://www.petercorke.com/RVC/common/toolboxhelp.css">
    <title>M-File Help: Bicycle</title>
  </head>
  <body>
  <table border="0" cellspacing="0" width="100%">
    <tr class="subheader">
      <td class="headertitle">M-File Help: Bicycle</td>
      <td class="subheader-left"><a href="matlab:open Bicycle">View code for Bicycle</a></td>
    </tr>
  </table>
<h1>Bicycle</h1><p><span class="helptopic">Car-like vehicle class</span></p><p>
This concrete class models the kinematics of a car-like vehicle (bicycle
or Ackerman model) on a plane.  For given steering and velocity inputs it
updates the true vehicle state and returns noise-corrupted odometry
readings.

</p>
<h2>Methods</h2>
<table class="list">
  <tr><td style="white-space: nowrap;" class="col1"> Bicycle</td> <td>constructor</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> add_driver</td> <td>attach a driver object to this vehicle</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> control</td> <td>generate the control inputs for the vehicle</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> deriv</td> <td>derivative of state given inputs</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> init</td> <td>initialize vehicle state</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> f </td> <td>predict next state based on odometry</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> Fx</td> <td>Jacobian of f wrt x</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> Fv</td> <td>Jacobian of f wrt odometry noise</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> update</td> <td>update the vehicle state</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> run</td> <td>run for multiple time steps</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> step</td> <td>move one time step and return noisy odometry</td></tr>
</table>
<h2>Plotting/display methods</h2>
<table class="list">
  <tr><td style="white-space: nowrap;" class="col1"> char</td> <td>convert to string</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> display</td> <td>display state/parameters in human readable form</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> plot</td> <td>plot/animate vehicle on current figure</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> plot_xy</td> <td>plot the true path of the vehicle</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> Vehicle.plotv</td> <td>plot/animate a pose on current figure</td></tr>
</table>
<h2>Properties (read/write)</h2>
<table class="list">
  <tr><td style="white-space: nowrap;" class="col1"> x </td> <td>true vehicle state: x, y, theta (3x1)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> V </td> <td>odometry covariance (2x2)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> odometry</td> <td>distance moved in the last interval (2x1)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> rdim</td> <td>dimension of the robot (for drawing)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> L </td> <td>length of the vehicle (wheelbase)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> alphalim</td> <td>steering wheel limit</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> maxspeed</td> <td>maximum vehicle speed</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> T </td> <td>sample interval</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> verbose</td> <td>verbosity</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> x_hist</td> <td>history of true vehicle state (Nx3)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> driver</td> <td>reference to the driver object</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> x0</td> <td>initial state, restored on init()</td></tr>
</table>
<h2>Examples</h2>
<p>
Odometry covariance (per timstep) is

</p>
<pre style="width: 90%%;" class="examples">
V&nbsp;=&nbsp;diag([0.02,&nbsp;0.5*pi/180].^2);
</pre>
<p>
Create a vehicle with this noisy odometry

</p>
<pre style="width: 90%%;" class="examples">
v&nbsp;=&nbsp;Bicycle(&nbsp;'covar',&nbsp;diag([0.1&nbsp;0.01].^2&nbsp;);
</pre>
<p>
and display its initial state

</p>
<pre style="width: 90%%;" class="examples">
v
</pre>
<p>
now apply a speed (0.2m/s) and steer angle (0.1rad) for 1 time step

</p>
<pre style="width: 90%%;" class="examples">
odo&nbsp;=&nbsp;v.step(0.2,&nbsp;0.1)
</pre>
<p>
where odo is the noisy odometry estimate, and the new true vehicle state

</p>
<pre style="width: 90%%;" class="examples">
v
</pre>
<p>
We can add a driver object

</p>
<pre style="width: 90%%;" class="examples">
v.add_driver(&nbsp;RandomPath(10)&nbsp;)
</pre>
<p>
which will move the vehicle within the region -10&amp;lt;x&amp;lt;10, -10&amp;lt;y&amp;lt;10 which we
can see by

</p>
<pre style="width: 90%%;" class="examples">
v.run(1000)
</pre>
<p>
which shows an animation of the vehicle moving for 1000 time steps
between randomly selected wayoints.

</p>
<h2>Notes</h2>
<ul>
  <li>Subclasses the MATLAB handle class which means that pass by reference semantics
apply.</li>
</ul>
<h2>Reference</h2>
<p>
Robotics, Vision &amp; Control, Chap 6
Peter Corke,
Springer 2011

</p>
<h2>See also</h2>
<p>
<a href="RandomPath.html">RandomPath</a>, <a href="EKF.html">EKF</a></p>
<hr>
<a name="Bicycle"><h1>Bicycle.Bicycle</h1></a>
<p><span class="helptopic">Vehicle object constructor</span></p><p>
<strong>v</strong> = <span style="color:red">Bicycle</span>(<strong>options</strong>)  creates a <span style="color:red">Bicycle</span> object with the kinematics of a
bicycle (or Ackerman) vehicle.

</p>
<h2>Options</h2>
<table class="list">
  <tr><td style="white-space: nowrap;" class="col1">'steermax', M</td> <td>Maximu steer angle [rad] (default 0.5)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1">'accelmax', M</td> <td>Maximum acceleration [m/s2] (default Inf)</td></tr>
  <tr></tr>
  <tr></tr>  <tr><td style="white-space: nowrap;" class="col1">'covar', C</td> <td>specify odometry covariance (2x2) (default 0)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1">'speedmax', S</td> <td>Maximum speed (default 1m/s)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1">'L', L</td> <td>Wheel base (default 1m)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1">'x0', x0</td> <td>Initial state (default (0,0,0) )</td></tr>
  <tr><td style="white-space: nowrap;" class="col1">'dt', T</td> <td>Time interval (default 0.1)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1">'rdim', R</td> <td>Robot size as fraction of plot window (default 0.2)</td></tr>
  <tr><td style="white-space: nowrap;" class="col1"> 'verbose'</td> <td>Be verbose</td></tr>
</table>
<h2>Notes</h2>
<ul>
  <li>The covariance is used by a "hidden" random number generator within the class.</li>
  <li>Subclasses the MATLAB handle class which means that pass by reference semantics
apply.</li>
</ul>
<h2>Notes</h2>
<ul>
  <li>Subclasses the MATLAB handle class which means that pass by reference semantics
apply.</li>
</ul>
<hr>
<a name="char"><h1>Bicycle.char</h1></a>
<p><span class="helptopic">Convert to a string</span></p><p>
<strong>s</strong> = V.<span style="color:red">char</span>() is a string showing vehicle parameters and state in
a compact human readable format.

</p>
<h2>See also</h2>
<p>
<a href="Bicycle.display.html">Bicycle.display</a></p>
<hr>
<a name="deriv"><h1>Bicycle.deriv</h1></a>
<p><span class="helptopic">Time derivative of state</span></p><p>
<strong>dx</strong> = V.<span style="color:red">deriv</span>(<strong>T</strong>, <strong>x</strong>, <strong>u</strong>) is the time derivative of state (3x1) at the state
<strong>x</strong> (3x1) with input <strong>u</strong> (2x1).

</p>
<h2>Notes</h2>
<ul>
  <li>The parameter T is ignored but  called from a continuous time integrator such as ode45 or
Simulink.</li>
</ul>
<hr>
<a name="f"><h1>Bicycle.f</h1></a>
<p><span class="helptopic">Predict next state based on odometry</span></p><p>
<strong>xn</strong> = V.<span style="color:red">f</span>(<strong>x</strong>, <strong>odo</strong>) is the predicted next state <strong>xn</strong> (1x3) based on current
state <strong>x</strong> (1x3) and odometry <strong>odo</strong> (1x2) = [distance, heading_change].

</p>
<p>
<strong>xn</strong> = V.<span style="color:red">f</span>(<strong>x</strong>, <strong>odo</strong>, <strong>w</strong>) as above but with odometry noise <strong>w</strong>.

</p>
<h2>Notes</h2>
<ul>
  <li>Supports vectorized operation where X and XN (Nx3).</li>
</ul>
<hr>
<a name="Fv"><h1>Bicycle.Fv</h1></a>
<p><span class="helptopic">Jacobian df/dv</span></p><p>
<strong>J</strong> = V.<span style="color:red">Fv</span>(<strong>x</strong>, <strong>odo</strong>) is the Jacobian df/dv (3x2) at the state <strong>x</strong>, for
odometry input <strong>odo</strong> (1x2) = [distance, heading_change].

</p>
<h2>See also</h2>
<p>
<a href="Bicycle.F.html">Bicycle.F</a>, <a href="Vehicle.Fx.html">Vehicle.Fx</a></p>
<hr>
<a name="Fx"><h1>Bicycle.Fx</h1></a>
<p><span class="helptopic">Jacobian df/dx</span></p><p>
<strong>J</strong> = V.<span style="color:red">Fx</span>(<strong>x</strong>, <strong>odo</strong>) is the Jacobian df/dx (3x3) at the state <strong>x</strong>, for
odometry input <strong>odo</strong> (1x2) = [distance, heading_change].

</p>
<h2>See also</h2>
<p>
<a href="Bicycle.f.html">Bicycle.f</a>, <a href="Vehicle.Fv.html">Vehicle.Fv</a></p>
<hr>
<a name="update"><h1>Bicycle.update</h1></a>
<p><span class="helptopic">Update the vehicle state</span></p><p>
<strong>odo</strong> = V.<span style="color:red">update</span>(<strong>u</strong>) is the true odometry value for
motion with <strong>u</strong>=[speed,steer].

</p>
<h2>Notes</h2>
<ul>
  <li>Appends new state to state history property x_hist.</li>
  <li>Odometry is also saved as property odometry.</li>
</ul>
<hr>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr class="subheader" valign="top"><td>&nbsp;</td></tr></table>
<p class="copy">&copy; 1990-2014 Peter Corke.</p>
</body></html>